package com.xiaoxu.spzx.manager.controller;


import com.xiaoxu.spzx.manager.service.SysMenuService;
import com.xiaoxu.spzx.model.entity.system.SysMenu;
import com.xiaoxu.spzx.model.vo.common.Result;
import com.xiaoxu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    //菜单列表
    @GetMapping("/findNodes")
    public Result findAll(){
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //菜单增加
    @PostMapping("/save")
    public Result insertMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.insertMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //菜单修改
    @PutMapping("/updateById")
    public Result updateMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.updateMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    //删除菜单 这里 有子节点的菜单则不能删除

    @DeleteMapping("/removeById/{id}")
    public Result deleteMenu(@PathVariable("id") Long id){
        sysMenuService.deleteMenu(id);
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }


}
